package com.py.payment.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.py.payment.dto.ret.PlanInfoRetDto;
import com.py.payment.dto.ret.PlanRecordsRetDto;
import com.py.payment.entity.PlanInfo;
import com.py.payment.entity.PlanRecords;
import com.py.payment.service.PlanInfoService;
import com.py.payment.service.PlanRecordsService;
import com.py.payment.tools.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 预案
 */
@RestController
@RequestMapping("/plan")
@CrossOrigin(origins = "*")
public class PlanController {

    @Autowired
    private PlanInfoService planInfoService;

    @Autowired
    private PlanRecordsService planRecordsService;

    @PostMapping(name = "获取预案列表",path = "/getPlanList")
    public ResponseData getPlanList(){
        QueryWrapper<PlanInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        List<PlanInfo> list = this.planInfoService.list(queryWrapper);
        return ResponseData.success(list);
    }

    @PostMapping(name = "获取预案记录",path = "/getPlanRecords")
    public ResponseData getPlanRecords(@RequestBody PlanRecords planRecords){
        List<PlanRecordsRetDto> planRecordsRetDtoList = this.planRecordsService.getPlanRecords(planRecords);
        return ResponseData.success(planRecordsRetDtoList);
    }

    @PostMapping(name = "设置预案触发条件",path = "/setPlan")
    public ResponseData setPlan(@RequestBody PlanInfo planInfo){
        this.planInfoService.updateById(planInfo);
        return ResponseData.success();
    }

}
